﻿using System;
using System.Runtime.Serialization;

namespace Emico.Linq.Criterion
{
    [Serializable]
    public abstract class SimpleExpression<T> : AbstractExpression<T>
        where T : class
    {
        #region Properties

        public object Value
        {
            get;
            private set;
        }

        public string PropertyName
        {
            get;
            private set;
        }

        #endregion

        #region Constructors

        public SimpleExpression(string propertyName, object value)
        {
            if(string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            this.PropertyName = propertyName;
            this.Value = value;
        }

        protected SimpleExpression(SerializationInfo info, StreamingContext context)
        {
            this.Value = info.GetValue("Value", typeof(object));
            this.PropertyName = info.GetString("PropertyName");
        }

        #endregion

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Value", this.Value);
            info.AddValue("PropertyName", this.PropertyName);
        }
    }
}
